package com.example.shopcardemo;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.ObjectMapper;

 

public class PurchaseNewBean {
	
	
	   /* product_id : 2
銆�銆�銆�銆�dId : 3
銆�銆�銆�銆�product_name : 鑻规灉
銆�銆�銆�銆�image : http://fruitsimage.qiniudn.com/b1797371-577c-4d82-a472-d4653cb5c0ee
銆�銆�銆�銆�unit_price : 12.00
銆�銆�銆�銆�product_unit : 1 鏂�
銆�銆�銆�銆�status : 1
銆�銆�銆�銆�description : 娴嬭瘯鎻忚堪*/
	
	private String product_id;
	private String dId;
	private String product_name;
	private String image;
	private double unit_price;
	private String product_unit;
	private String status;
	private String description;
	
	
	
	private String number;
	
	
	
	public String getNumber() {
		return number;
	}
	public void setNumber(String number) {
		this.number = number;
	}
	
	
	public String getProduct_id() {
		return product_id;
	}
	public void setProduct_id(String product_id) {
		this.product_id = product_id;
	}
	public String getdId() {
		return dId;
	}
	public void setdId(String dId) {
		this.dId = dId;
	}
	public String getProduct_name() {
		return product_name;
	}
	public void setProduct_name(String product_name) {
		this.product_name = product_name;
	}
	public String getImage() {
		return image;
	}
	public void setImage(String image) {
		this.image = image;
	}
	public double getUnit_price() {
		return unit_price;
	}
	public void setUnit_price(double unit_price) {
		this.unit_price = unit_price;
	}
	public String getProduct_unit() {
		return product_unit;
	}
	public void setProduct_unit(String product_unit) {
		this.product_unit = product_unit;
	}
	public String getStatus() {
		return status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	
	
	public static List<PurchaseNewBean> parsePurchaseNewList(InputStream inputStream){
		List<PurchaseNewBean> list=new ArrayList<PurchaseNewBean>();
		
		ObjectMapper mapper = new ObjectMapper();
		
		try {
			Iterator<JsonNode> jsonNodeList = mapper.readTree(inputStream).path("data").getElements();
			
			while(jsonNodeList.hasNext()) {
				JsonNode childNode = jsonNodeList.next();
				list.add(mapper.readValue(childNode, PurchaseNewBean.class));
			}
			
		} catch (JsonProcessingException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		return list;
	}
	
	public static PurchaseNewBean parsePurchaseBean(InputStream inputStream){
		ObjectMapper mapper = new ObjectMapper();
		try {
			JsonNode path = mapper.readTree(inputStream).path("data");
			return mapper.readValue(path, PurchaseNewBean.class);
		} catch (JsonProcessingException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	
	

}
